package uk.ac.cam.djjb2.mygame;

import java.io.DataOutput;
import java.io.IOException;

public abstract class ReplicaBase implements Replica {

	private final int id;
	private final ReplicaManager manager;
	private boolean destroyed;
	
	public ReplicaBase(ReplicaManager manager) throws ReplicationException {
		this.manager = manager;
		this.id = manager.allocateId(this);
	}
	
	@Override
	public int getId() {
		return id;
	}
	
	public boolean isDestroyed() {
		return destroyed;
	}
	
	@Override
	public ReplicaManager getReplicaManager() {
		return manager;
	}
	
	@Override
	public boolean shouldExist(Client client) {
		return !destroyed;
	}
	@Override
	public boolean shouldUpdate(Client client) {
		return !destroyed;
	}
	@Override
	public void sendCreateMessage(Client client, DataOutput message)
			throws IOException {
	}
	@Override
	public void sendDestroyMessage(Client client, DataOutput message)
			throws IOException {
	}
	@Override
	public void sendUpdateMessage(Client client, DataOutput message)
			throws IOException {
	}
	public void destroy() {
		destroyed = true;
	}
	@Override
	public boolean postUpdate() {
		return destroyed;
	}
}
